/**
 * @project lauwsys
 */
package com.chimoz.lauwsys.repository.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.chimoz.lauwsys.domain.Agent;
import com.chimoz.lauwsys.repository.AgentRepository;

/**
 * @author Christian Teguh
 * @created 3 Okt 2011 20.54.33
 */
@Repository
public class JAgentRepository implements AgentRepository {

	@Value("${jdbc.sql.agent.insert}")
	private String insertAgentQuery;
	
	@Value("${jdbc.sql.agent.update}")
	private String updateAgentQuery;
	
	@Value("${jdbc.sql.agent.remove}")
	private String removeAgentQuery;
	
	@Value("${jdbc.sql.agent.queryById}")
	private String agentByIdQuery;
	
	@Autowired
	private SimpleJdbcTemplate simpleJdbcTemplate;
	
	
	public Agent saveAgent(Agent agent) {
		
		return null;
	}

	public void removeAgent(Agent agent) {
		// TODO Auto-generated method stub
		
	}

	public Agent getAgentById(Long id) {
		return simpleJdbcTemplate.queryForObject(agentByIdQuery, agentRowMapper, id);
	}

	public List<Agent> listAgent(String criteria) {
		// TODO Auto-generated method stub
		return null;
	}
	
	private RowMapper<Agent> agentRowMapper = new RowMapper<Agent>() {
		public Agent mapRow(ResultSet rs, int i) throws SQLException {
			  Agent agent = new Agent();
			  agent.setId(rs.getLong("agent_id"));
			  agent.setCode(rs.getString("agent_code"));
			  agent.setDesc(rs.getString("agent_desc"));
			  agent.setCtime(rs.getInt("agent_ctime"));
			  agent.setMtime(rs.getInt("agent_mtime"));
			  agent.setName(rs.getString("agent_name"));
			  agent.setPoLimitBtr(rs.getInt("agent_po_limit_btr"));
			  agent.setPoLimitSwt(rs.getInt("agent_po_limit_swt"));
		      return agent;
		}
	};

}
